Cottus.addRule   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import { toArray } from 'myrmidon';
2
import Validator from './Validator';
3
4
export default class Cottus {
5
    constructor(conf = {}) {
6
        this.rules = {};
7
        this.addRules(conf.rules || []);
8
    }
9
10
    compile(schema, parentContext) {
11
        const validator = new Validator(this, schema, parentContext);
12
13
        validator.parse();
14
15
        return validator;
16
    }
17
18
    addRules(rules) {
19
        rules.forEach(rule => {
20
            toArray(rule.schema).forEach(schemaKey => this.rules[schemaKey] = rule);
21
        });
22
    }
23
24
    addRule(rule) {
25
        this.addRules([ rule ]);
26
    }
27
}
28